// Copyright (c) 2023 Presto Labs Pte. Ltd.
// Author: tianqiang

#pragma once

#include <functional>
#include <string>
#include <unordered_map>
#include <vector>

#include "coin/proto/coin_order_gateway.pb.h"
#include "coin/proto/coin_query.pb.h"

namespace coin2::exchange::base::order {

class RiskUndetectedPosition {
 public:
  using ProductPosition = coin::proto::ProductPosition;
  using RiskEventHandler = std::function<void(const coin::proto::RiskEvent&)>;

  void HandleUndetectedPosition(std::vector<ProductPosition>&& undetected_position);

  void ManageRisk(int64_t ts);

  void RegisterRiskEventHandler(RiskEventHandler risk_event_handler) {
    risk_event_handler_ = risk_event_handler;
  }

 private:
  int64_t last_update_timestamp_ = 0;
  std::unordered_map<std::string, ProductPosition> undetected_position_map_;
  RiskEventHandler risk_event_handler_;
};

}  // namespace coin2::exchange::base::order
